home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
gtalk
/
gtalkStream.pyo
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2008-10-13
|
4KB
|
108 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from pyxmpp import sasl
from pyxmpp.exceptions import SASLNotAvailable, SASLMechanismNotAvailable, SASLAuthenticationFailed, FatalStreamError
from jabber.threadstream import ThreadStream
from pyxmpp.streamsasl import SASL_NS
from pyxmpp.streambase import STREAM_NS
from pyxmpp.jid import JID
import libxml2
from logging import getLogger
log = getLogger('gtalkStream')
GTALK_AUTH_NS = 'http://www.google.com/talk/protocol/auth'
class GoogleTalkStream(ThreadStream):
def stream_start(self, doc):
self.doc_in = doc
log.debug('input document: %r' % (self.doc_in.serialize(),))
try:
r = self.doc_in.getRootElement()
if r.ns().getContent() != STREAM_NS:
self._send_stream_error('invalid-namespace')
raise FatalStreamError, 'Invalid namespace.'
except libxml2.treeError:
self._send_stream_error('invalid-namespace')
raise FatalStreamError, "Couldn't get the namespace."
self.version = r.prop('version')
if self.version and self.version != '1.0':
self._send_stream_error('unsupported-version')
raise FatalStreamError, 'Unsupported protocol version.'
if self.initiator:
self.stream_id = r.prop('id')
peer = r.prop('from')
if peer:
peer = JID(peer)
self.peer = peer
else:
to = r.prop('to')
if to:
to = self.check_to(to)
if not to:
self._send_stream_error('host-unknown')
raise FatalStreamError, 'Bad "to"'
self.me = JID(to)
self._send_stream_start(self.generate_id())
self._send_stream_features()
self.state_change('fully connected', self.peer)
self._post_connect()
if not self.version:
self.state_change('fully connected', self.peer)
self._post_connect()
def _sasl_authenticate(self, username, authzid, mechanism = None):
if not self.initiator:
raise SASLAuthenticationFailed, 'Only initiating entity start SASL authentication'
while not self.features:
self._GoogleTalkStream__logger.debug('Waiting for features')
self._read()
if not self.peer_sasl_mechanisms:
raise SASLNotAvailable, "Peer doesn't support SASL"
if not mechanism:
mechanism = None
for m in self.sasl_mechanisms:
if m in self.peer_sasl_mechanisms:
mechanism = m
break
continue
if not mechanism:
raise SASLMechanismNotAvailable, "Peer doesn't support any of our SASL mechanisms"
self._GoogleTalkStream__logger.debug('Our mechanism: %r' % (mechanism,))
elif mechanism not in self.peer_sasl_mechanisms:
raise SASLMechanismNotAvailable, '%s is not available' % (mechanism,)
self.auth_method_used = 'sasl:' + mechanism
self.authenticator = sasl.client_authenticator_factory(mechanism, self)
initial_response = self.authenticator.start(username, authzid)
if not isinstance(initial_response, sasl.Response):
raise SASLAuthenticationFailed, 'SASL initiation failed'
root = self.doc_out.getRootElement()
xmlnode = root.newChild(None, 'auth', None)
ns = xmlnode.newNs(SASL_NS, None)
xmlnode.setNs(ns)
xmlnode.setProp('mechanism', mechanism)
ga = xmlnode.newNs(GTALK_AUTH_NS, 'ga')
xmlnode.newNsProp(ga, 'client-uses-full-bind-result', 'true')
if initial_response.data:
xmlnode.setContent(initial_response.base64())
self._write_raw(xmlnode.serialize(encoding = 'UTF-8'))
xmlnode.unlinkNode()
xmlnode.freeNode()